<div class="widget">
	<div class="widget-header bg-blue">
		<i class="widget-icon icon-notebook"></i> 
		<span class="widget-caption"> 新增客户 </span>
		<div class="widget-buttons">
			<a href="javascript:void(0);" onclick="handlerCancel(this);" title="关闭"
				 data-toggle="dispose" data-refresh-table="#table-customer"> <i class="fa fa-times"></i> </a> 
		</div>
	</div>
	<div class="widget-body">
		<!-- TODO 基本信息 -->
		<div class="widget radius-bordered mgbt-xs-10">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> 基本信息 </span>
			</div>
			<div class="widget-body editor-body-sm">
				<form class="form-horizontal form-editor form-editor-customer">
					<div class="row">
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label" for="code">客户编号</label>
								<div class="col-sm-8">
									<input name="id" id="customerid" type="hidden" class="form-control">
									<input name="code" id="code" type="text" class="form-control" readonly="readonly" disabled="disabled">
								</div>
							</div>
						</div>
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label" for="createDate">加入时间</label>
								<div class="col-sm-8">
									<div class="input-group date date-selector">
										<input name="createDate" id="createDate" type="text" class="form-control"> 
										<span class="input-group-addon">
											<span class="fa fa-calendar"></span>
										</span>
									</div>
								</div>
							</div>
						</div>
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label" for="username">课程顾问</label>
								<div class="col-sm-8">
									<div class="input-group">
										<input name="username" id="username" type="text" class="form-control" readonly="readonly"> 
										<span class="input-group-btn">
											<a class="btn btn-default" onclick="handlerModal(this, 'content/esm/customer/dialog/adviser.html', 'createAdviser')">
												<i class="fa fa-ellipsis-h"></i>
											</a>
										</span>
									</div>
									<input type="hidden" name="userid" id="userid" data-default-user/>
								</div>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label" for="market">市场渠道</label>
								<div class="col-sm-8">
									<select name="market" id="market" class="chosen-select" data-url="/miwawa/default/common/select.json" data-pcode="c_market_type" data-entity="com.app.miwawa.api.system.entity.config.Codec">
									</select>
								</div>
							</div>
						</div>
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label" for="source">信息来源</label>
								<div class="col-sm-8">
									<select name="source" id="source" class="chosen-select" data-url="/miwawa/default/common/select.json"  data-pcode="c_source_type" data-entity="com.app.miwawa.api.system.entity.config.Codec">
									</select>
								</div>
							</div>
						</div>
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label" for="parentName">转介绍人</label>
								<div class="col-sm-8">
									<input name="parentName" id="parentName" type="text" class="form-control"> 
									<input name="parentId" type="hidden">
								</div>
							</div>
						</div>
					</div>
					<div class="widget-footer editor-footer-sm">
						<button type="button" class="btn btn-danger btn-sm" title="取消" 
										data-toggle="tooltip" data-placement="top" 
										data-refresh-table="#table-customer"
										onclick="handlerCancel(this, 'editor-wrapper-open');">
							<i class="glyphicon glyphicon-remove"></i>
						</button>
						<button type="button" class="btn btn-primary btn-sm" title="保存"
										data-toggle="tooltip" data-placement="top" 
										onclick="handlerSubmit(this, '#editor-form-customer', '.form-editor-customer');">
							<i class="glyphicon glyphicon-ok"></i>
						</button>
					</div>
				</form>
			</div>
		</div>
		<!-- TODO 家长信息 -->
		<div class="widget radius-bordered mgbt-xs-10 hidden" id="editor-panel-parents">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> <a href="" data-toggle="collapse"> 家长信息 </a> </span>
				<div class="widget-buttons buttons-bordered">
					<button class="btn btn-default btn-sm" title="添加" 
									data-toggle="tooltip" data-placement="top" 
									data-tool="append" 
									data-template-id="#form-parent-template" 
									data-template-path="/miwawa/content/esm/customer/template.html" 
									data-template-target=".editor-body-parents"
									data-loaded="handlerParents">
						<i class="fa fa-plus"></i>
					</button>
					<button class="btn btn-default btn-sm" title="删除" 
									data-toggle="tooltip" data-placement="top" 
									data-tool="remove" data-template-target=".editor-body-parents"
									data-remove-action="/miwawa/{dbname}/parents/delete/{id}">
						<i class="fa fa-minus"></i>
					</button>
				</div>
				<div class="widget-buttons compact">
					<a href="" data-toggle="collapse"> <i class="fa fa-compress"></i> </a> 
				</div>
			</div>
			<div class="widget-body editor-body-sm editor-body-parents">
				<form class="form-horizontal form-editor form-editor-parents form-editor-parents-0">
					<input type="hidden" name="status" value="true">
					<div class="row" data-dynamic-template>
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label">关系</label>
								<div class="col-sm-8">
									<select name="relation" id="relation" class="chosen-select" data-url="/miwawa/default/common/select.json" data-pcode="c_parent_title" data-entity="com.app.miwawa.api.system.entity.config.Codec">
									</select>
								</div>
							</div>
						</div>
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label">姓名</label>
								<div class="col-sm-8">
									<input name="customerId" id="customerId" type="hidden">
									<input name="name" type="text" class="form-control">
								</div>
							</div>
						</div>
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label required">手机</label>
								<div class="col-sm-8">
									<input name="mobile" type="text" id="mobile" class="form-control" maxlength="11" required="required" 
												 data-bv-stringlength="true" 
												 data-bv-stringlength-min="11" 
												 data-bv-stringlength-max="11">
								</div>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label">APP昵称</label>
								<div class="col-sm-8">
									<input name="app" type="text" class="form-control">
								</div>
							</div>
						</div>
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label">微信</label>
								<div class="col-sm-8">
									<input name="wechat" type="text" class="form-control">
								</div>
							</div>
						</div>
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label">Email</label>
								<div class="col-sm-8">
									<input name="email" type="text" class="form-control">
								</div>
							</div>
						</div>
					</div>
					<div class="widget-footer editor-footer-sm">
						<button type="button" class="btn btn-danger btn-sm" title="取消" 
										data-toggle="tooltip" data-placement="top" 
										data-refresh-table="#table-customer"
										onclick="handlerCancel(this);">
							<i class="glyphicon glyphicon-remove"></i>
						</button>
						<button type="button" class="btn btn-primary btn-sm" title="保存" 
										data-toggle="tooltip" data-placement="top" 
										onclick="holdup(this, '#editor-form-parents', '.form-editor-parents-0');" data-submit-callback="handlerParents">
							<i class="glyphicon glyphicon-ok"></i>
						</button>
					</div>
				</form>
			</div>
		</div>
		<!-- TODO 宝宝信息 -->
		<div class="widget radius-bordered hidden" id="editor-panel-student">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> <a href="" data-toggle="collapse"> 宝宝信息 </a> </span>
				<div class="widget-buttons buttons-bordered">
					<button class="btn btn-default btn-sm" title="添加" 
									data-toggle="tooltip" data-placement="top" 
									data-tool="append" 
									data-template-id="#form-student-template" 
									data-template-path="/miwawa/content/esm/customer/template.html" 
									data-template-target=".editor-body-student"
									data-loaded="handlerStudent">
						<i class="fa fa-plus"></i>
					</button>
					<button class="btn btn-default btn-sm" title="删除" 
									data-toggle="tooltip" data-placement="top" 
									data-tool="remove" data-template-target=".editor-body-student">
						<i class="fa fa-minus"></i>
					</button>
				</div>
				<div class="widget-buttons compact">
					<a href="" data-toggle="collapse"> <i class="fa fa-compress"></i> </a> 
				</div>
			</div>
			<div class="widget-body editor-body-sm editor-body-student">
				<form class="form-horizontal form-editor form-editor-student-0">
					<div class="row" data-dynamic-template>
						<div class="col-sm-12">
							<div class="row">
								<div class="col-sm-4">
									<div class="form-group">
										<label class="col-sm-4 control-label required">姓名</label>
										<div class="col-sm-8">
											<input name="name" type="text" class="form-control" required="required">
										</div>
									</div>
								</div>
								<div class="col-sm-4">
									<div class="form-group">
										<label class="col-sm-4 control-label">昵称</label>
										<div class="col-sm-8">
											<input name="nick" type="text" class="form-control">
										</div>
									</div>
								</div>
								<div class="col-sm-4">
									<div class="form-group">
										<label class="col-sm-4 control-label">性别</label>
										<div class="col-sm-8">
											<select name="sex" id="sex" class="form-control">
												<option value="男宝宝">男宝宝</option>
												<option value="女宝宝">女宝宝</option>
											</select>
										</div>
									</div>
								</div>
							</div>
							<div class="row">						
								<div class="col-sm-4">
									<div class="form-group">
										<label class="col-sm-4 control-label">生日</label>
										<div class="col-sm-8">
											<div class="input-group date date-selector">
												<input name="birthday" id="birthday" type="text" class="form-control"> 
												<span class="input-group-addon"> <span class="fa fa-calendar"></span> </span>
											</div>
										</div>
									</div>
								</div>
								<div class="col-sm-8">
									<div class="form-group">
										<label class="col-sm-2 control-label">备注</label>
										<div class="col-sm-10">
											<input name="remark" type="text" class="form-control" maxlength="30" placeholder="最多可填写30个字">
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="widget-footer editor-footer-sm editor-tools-student">
						<button type="button" class="btn btn-danger btn-sm" title="取消" 
										data-toggle="tooltip" data-placement="top" 
										data-refresh-table="#table-customer"
										onclick="handlerCancel(this);">
							<i class="glyphicon glyphicon-remove"></i>
						</button>
						<button type="button" class="btn btn-primary btn-sm" title="保存"
										data-toggle="tooltip" data-placement="top"
										onclick="checkBirthday(this, '#editor-form-student', '.form-editor-student-0');" data-submit-callback="handlerStudent">
							<i class="glyphicon glyphicon-ok"></i>
						</button>
					</div>
				</form>
			</div>
		</div>
		
		<!-- TODO 家庭住址 -->
		<div class="widget radius-bordered collapsed hidden" id="editor-panel-address">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> <a href="" data-toggle="collapse"> 家庭住址 </a> </span>
				<div class="widget-buttons compact">
					<a href="" data-toggle="collapse"> <i class="fa fa-expand"></i> </a> 
				</div>
			</div>
			<div class="widget-body editor-body-sm">
				<form class="form-horizontal form-editor form-editor-address">
					<div class="row">
						<div class="col-sm-1">
							<div class="form-group">
								<label class="col-sm-12 control-label" for="province">地区</label>
							</div>
						</div>
						<div class="col-sm-2">
							<div class="form-group">
								<div class="col-sm-12">
									<div class="input-group">
										<select name="province" class="chosen-select" id="province">
											<option value="310000">上海</option>
										</select> 
										<span class="input-group-addon">省</span>
									</div>
								</div>
							</div>
						</div>
						<div class="col-sm-3">
							<div class="form-group">
								<div class="col-sm-12">
									<div class="input-group">
										<select name="prefecture" class="chosen-select" id="prefecture">
											<option value="310100">上海</option>
										</select> 
										<span class="input-group-addon">市</span>
									</div>
								</div>
							</div>
						</div>
						<div class="col-sm-3">
							<div class="form-group">
								<div class="col-sm-12">
									<div class="input-group">
										<select name="county" class="chosen-select" id="county">
										</select> 
										<span class="input-group-addon">区县</span>
									</div>
								</div>
							</div>
						</div>
						<div class="col-sm-3">
							<div class="form-group">
								<div class="col-sm-12">
									<div class="input-group">
										<span class="input-group-addon">邮编</span>
										<input name="zipcode" id="zipcode" type="text" class="form-control">
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-sm-1">
							<div class="form-group">
								<label class="col-sm-12 control-label" for="detail">地址</label>
							</div>
						</div>
						<div class="col-sm-8">
							<div class="form-group">
								<div class="col-sm-12">
									<input name="detail" id="detail" type="text" class="form-control">
								</div>
							</div>
						</div>
						<div class="col-sm-3">
							<div class="form-group">
								<div class="col-sm-12">
									<div class="input-group">
										<span class="input-group-addon">电话</span>
										<input name="telephone" id="telephone" type="text" class="form-control">
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="widget-footer editor-footer-sm editor-tools-address">
						<button type="button" class="btn btn-danger btn-sm" title="取消" 
										data-toggle="tooltip" data-placement="top" 
										data-refresh-table="#table-customer"
										onclick="handlerCancel(this);">
							<i class="glyphicon glyphicon-remove"></i>
						</button>
						<button type="button" class="btn btn-primary btn-sm" title="保存"
										data-toggle="tooltip" data-placement="top"
										onclick="handlerSubmit(this, '#editor-form-address', '.form-editor-address');">
							<i class="glyphicon glyphicon-ok"></i>
						</button>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>

<!-- 提交表单 ========================================================= -->
<form id="editor-form-customer" action="/miwawa/{dbname}/customer/save" method="post" 
			name="com.app.miwawa.api.esm.entity.customer.Customer" 
			data-show-target="#editor-panel-parents" 
			data-custom-action="true">
			<input type="hidden" name="status" value="0">
			<input type="hidden" name="invalid" value="F">
</form>
<form id="editor-form-parents" action="/miwawa/{dbname}/parents/save" method="post" 
			name="com.app.miwawa.api.esm.entity.customer.Parents" 
			data-show-target="#editor-panel-student" 
			data-custom-action="true">
</form>
<form id="editor-form-student" action="/miwawa/{dbname}/common/save" method="post" 
			name="com.app.miwawa.api.esm.entity.customer.Student" 
			data-show-target='["#editor-panel-address","#editor-panel-selling","#editor-panel-bespoke"]' 
			data-foreign-src="#editor-form-customer" 
			data-foreign-key="com.app.miwawa.api.esm.entity.customer.Customer">
			<input type="hidden" name="bean['status']" value="0">
			<input type="hidden" name="bean['invalid']" value="F">
			<input type="hidden" name="bean['customerId']" data-foreign-id>
</form>
<form id="editor-form-address" action="/miwawa/{dbname}/common/save" method="post" 
			name="com.app.miwawa.api.esm.entity.customer.Address" 
			data-foreign-src="#editor-form-customer" 
			data-foreign-key="com.app.miwawa.api.esm.entity.customer.Customer">
			<input type="hidden" name="bean['status']" value="0">
			<input type="hidden" name="bean['invalid']" value="F">
			<input type="hidden" name="bean['customerId']" data-foreign-id>
</form>
    
<script type="text/javascript">
<!--
	jQuery(function() {
		require(['jquery.plugin.form'],function(form){
			form.datepicker(".date-selector");
			form.tooltip("[data-toggle='tooltip']");
			form.chosen("#market").select("#market");
			form.chosen("#source").select("#source");
			form.chosen("#relation").select("#relation");
			form.chosen("#province,#prefecture,#county").region("#county",{"pid":"310100"});
			
			jQuery("#userid",".form-editor-customer").val(userid);
			jQuery("#username",".form-editor-customer").val(username);
			
		});
		
		jQuery("[data-toggle='table']").bootstrapTable();
	});
	
	function judge(form){
		var parentForm = jQuery(".form-editor-parents");
		parentForm.each(function(i,n){
		 	if(i<=0){
				jQuery('#parStatus',form).val('true');
		 	}else{
				jQuery('#parStatus',form).val('false');
		 	} 
		});
	}
	
	function holdup(botton, table, form){
		if((/^1(3|4|5|7|8)\d{9}$/).test(jQuery("#mobile",form).val()) == false){
			jQuery.message.alert("请输入正确的手机号");
			return;
		}else{
			jQuery.ajaxsend({
				url:"/miwawa/{dbname}/common/search.json".replace("{dbname}",dbname),
				data:{
							"entityClass":"com.app.miwawa.api.esm.entity.customer.Parents",
							"and[0][operator]": "EQ",
					    "and[0][fieldName]": "mobile",				
		          "and[0][fieldValue]": jQuery("#mobile",form).val()
				},
				success:function(data){
					var counts = data.rows;
					if(counts.length > 0){
						jQuery.message.alert("此手机号已存在，请更换。");
						return;
					}
					var customerId =  jQuery("#customerid",".form-editor-customer").val();
					jQuery("#customerId",form).val(customerId);
					handlerSubmit(botton, table, form);
				}
			});
		}
	}

//-->
</script>